const IBL = {
	/* 业务图层 */
	overlayLayers: {},
	/* 基础底图 */
	baseLayers: [],
	/* 默认显示的图层 */
	defaultLayer: [],
	//用于编辑的建筑图层
	editPolygonLayer: null,
	//建筑标注图层
	labels: {},

	bussid: "",
	init: function() {
		this._initTDT();
		this._initFeatureLayer()
		this._initRegion();
	},
	_initTDT: function() {
		/* 开始天地图数据 */
		var normalm = L.tileLayer.chinaProvider('TianDiTu.Normal.Map', {
				maxZoom: 18,
				minZoom: 5
			}),
			normala = L.tileLayer.chinaProvider('TianDiTu.Normal.Annotion', {
				maxZoom: 18,
				minZoom: 5
			}),
			imgm = L.tileLayer.chinaProvider('TianDiTu.Satellite.Map', {
				maxZoom: 18,
				minZoom: 5
			}),
			imga = L.tileLayer.chinaProvider('TianDiTu.Satellite.Annotion', {
				maxZoom: 18,
				minZoom: 5
			});
		/* 设置默认底图 */
		var img = L.layerGroup([imgm, imga]);
		var normal = L.layerGroup([normalm, normala]);
		this.defaultLayer.push(img);
		/* 设置全部底图 */
		this.baseLayers = {
			"基础影像": img,
			"电子地图": normal,
		}
		/* 结束天地图 */
	},
	_initRegion: function() {
		this.overlayLayers["区域范围"] = L.layerGroup([L.geoJson(statesData, {
			style: function(feature) {
				return {
					color: '#F8F8FF',
					weight: 2,
					opacity: 1,
					dashArray: '3',
					fillOpacity: 0.0
				};
			}
		})]);
	},
	_initFeatureLayer: function() {
		this.editPolygonLayer = L.esri.featureLayer({
			url: 'http://103.231.146.5:6080/arcgis/rest/services/JW/testpolygon/FeatureServer/0',
			simplifyFactor: 0.5,
			precision: 5,
			style: function(feature) {
				if (feature.properties.id == null || feature.properties.id == "null") {
					return {
						color: 'white',
						weight: 2,
						opacity: 1,
						fillColor: "#E31A1C",
						fillOpacity: 0.7
					};
				} else {
					return {
						color: 'white',
						weight: 2,
						opacity: 1,
						fillColor: "#3388FF",
						fillOpacity: 0.7
					};
				}
			}
		});
		var that = this;

		this.editPolygonLayer.on('createfeature', function(e) {
			labels = {};
			var id = e.feature.id;
			var feature = that.editPolygonLayer.getFeature(id);
			var center = feature.getBounds().getCenter();

			var text = "";
			if (e.feature.properties[that.bussid] == null || e.feature.properties[that.bussid] == "null") {
				text = "";
			} else {
				text = e.feature.properties[that.bussid];
				var label = L.marker(center, {
					icon: L.divIcon({
						iconSize: null,
						className: 'label',
						html: '<div>' + text + '</div>'
					})
				})
				that.labels[id] = label;
			}
		});

		//绑定气泡
		/* 	this.editPolygonLayer.bindPopup(function(layer) {
				return L.Util.template('<p>{id}<br>{name}</p>', layer.feature.properties);
			}); */
		var lg = L.layerGroup([this.editPolygonLayer]);
		this.overlayLayers["绘制地块"] = lg;
		this.defaultLayer.push(lg);
	}
};
